//
//  BasisValueExt.swift
//  TwoGame
//
//  Created by pro on 2017/9/5.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

import Foundation
import UIKit

// MARK: swift基础类型简易转化
protocol BasalValueconversion {
    
    var int: Int {get}
    var float: Float {get}
    var double: Double {get}
    var cgFloat: CGFloat {get}
}

extension Float: BasalValueconversion {
    var float: Float {
        return self
    }
    var double: Double {
        return Double(self)
    }
    var int: Int {
        return Int(self)
    }
    var cgFloat: CGFloat {
        return CGFloat(self)
    }
}
extension Int: BasalValueconversion {
    
    var float: Float {
        return Float(self)
    }
    var double: Double {
        return Double(self)
    }
    var int: Int {
        return self
    }
    var cgFloat: CGFloat {
        return CGFloat(self)
    }
}

extension Double: BasalValueconversion {
    
    var float: Float {
        return Float(self)
    }
    var double: Double {
        return self
    }
    var int: Int {
        return Int(self)
    }
    var cgFloat: CGFloat {
        return CGFloat(self)
        
    }
}
extension CGFloat: BasalValueconversion {
    
    var float: Float {
        return Float(self)
    }
    var double: Double {
        return Double(self)
    }
    var int: Int {
        return Int(self)
    }
    var cgFloat: CGFloat {
        return self
    }
}




// MARK: ------ 浮点数保留位数
protocol FloatingPointFormat {
    func format(_ f: String) -> String
}
extension Double: FloatingPointFormat {
    func format(_ f: String) -> String {
        return String(format: "%\(f)lf", self)
    }
}
extension Float: FloatingPointFormat {
    func format(_ f: String) -> String {
        return String(format: "%\(f)f", self)
    }
}
extension CGFloat: FloatingPointFormat {
    func format(_ f: String) -> String {
        return String(format: "%\(f)lf", self)
    }
}
